/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package javaapplication1;

import java.awt.Toolkit;
import java.util.ArrayList;
import java.util.Random;

/**
 *
 * @author C064
 */
public class ChooseByRandomJFrame extends javax.swing.JFrame {

    /** Creates new form ChooseByRandomJFrame */
    public ChooseByRandomJFrame() {
        initComponents();
        super.setTitle("彩票购买抽奖程序");
        int width = Toolkit.getDefaultToolkit().getScreenSize().width;
		int height = Toolkit.getDefaultToolkit().getScreenSize().height;
		super.setLocation((width - 400) / 2, (height - 350) / 2);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        Num1Label = new javax.swing.JLabel();
        Num2Label = new javax.swing.JLabel();
        Num3Label = new javax.swing.JLabel();
        Num4Label = new javax.swing.JLabel();
        Num5Label = new javax.swing.JLabel();
        Num6Label = new javax.swing.JLabel();
        Num7Label = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        OKButton = new javax.swing.JButton();
        Num2Field = new javax.swing.JTextField();
        Num1Field = new javax.swing.JTextField();
        Num3Field = new javax.swing.JTextField();
        Num4Field = new javax.swing.JTextField();
        Num5Field = new javax.swing.JTextField();
        Num6Field = new javax.swing.JTextField();
        Num7Field = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("宋体", 1, 24)); // NOI18N
        jLabel1.setText("随机选号");

        Num1Label.setFont(new java.awt.Font("宋体", 1, 14)); // NOI18N
        Num1Label.setText("1");

        Num2Label.setFont(new java.awt.Font("宋体", 1, 14)); // NOI18N
        Num2Label.setText("2");

        Num3Label.setFont(new java.awt.Font("宋体", 1, 14)); // NOI18N
        Num3Label.setText("3");

        Num4Label.setFont(new java.awt.Font("宋体", 1, 14)); // NOI18N
        Num4Label.setText("4");

        Num5Label.setFont(new java.awt.Font("宋体", 1, 14)); // NOI18N
        Num5Label.setText("5");

        Num6Label.setFont(new java.awt.Font("宋体", 1, 14)); // NOI18N
        Num6Label.setText("6");

        Num7Label.setFont(new java.awt.Font("宋体", 1, 14)); // NOI18N
        Num7Label.setText("7");

        jLabel9.setText("每注2元");

        jButton2.setText("返回");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        OKButton.setText("确认购买");
        OKButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                OKButtonActionPerformed(evt);
            }
        });

        Num2Field.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Num2FieldActionPerformed(evt);
            }
        });

        Num1Field.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Num1FieldActionPerformed(evt);
            }
        });

        Num3Field.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Num3FieldActionPerformed(evt);
            }
        });

        Num4Field.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Num4FieldActionPerformed(evt);
            }
        });

        Num5Field.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Num5FieldActionPerformed(evt);
            }
        });

        Num6Field.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Num6FieldActionPerformed(evt);
            }
        });

        Num7Field.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Num7FieldActionPerformed(evt);
            }
        });

        jButton1.setText("选号");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 16, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(OKButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton2)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(75, 75, 75)
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 79, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                            .addComponent(Num1Field, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(Num1Label)
                            .addComponent(Num5Field, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(Num5Label))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                            .addComponent(Num2Field, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(Num2Label)
                            .addComponent(Num6Field, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(Num6Label))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                            .addComponent(Num3Field, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(Num3Label)
                            .addComponent(Num7Field, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(Num7Label))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                            .addComponent(Num4Label)
                            .addComponent(Num4Field, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(19, 19, 19))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Num2Field, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Num1Field, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Num3Field, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Num4Field, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Num1Label)
                    .addComponent(Num2Label)
                    .addComponent(Num3Label)
                    .addComponent(Num4Label))
                .addGap(15, 15, 15)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Num5Field, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Num6Field, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Num7Field, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Num5Label)
                    .addComponent(Num6Label)
                    .addComponent(Num7Label))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 33, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(OKButton)
                    .addComponent(jLabel9)
                    .addComponent(jButton2)
                    .addComponent(jButton1))
                .addGap(19, 19, 19))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        new PurchaseJFrame().setVisible(true);
        this.setVisible(false);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void OKButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OKButtonActionPerformed
        
    }//GEN-LAST:event_OKButtonActionPerformed

    private void Num2FieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Num2FieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_Num2FieldActionPerformed

    private void Num1FieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Num1FieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_Num1FieldActionPerformed

    private void Num3FieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Num3FieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_Num3FieldActionPerformed

    private void Num4FieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Num4FieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_Num4FieldActionPerformed

    private void Num5FieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Num5FieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_Num5FieldActionPerformed

    private void Num6FieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Num6FieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_Num6FieldActionPerformed

    private void Num7FieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Num7FieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_Num7FieldActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        ArrayList<Integer> list = new ArrayList<Integer>();
        Random random = new Random();
        int i = 0, num = 0;
        while (i < 7) {
                num = random.nextInt(35) + 1;
                if (!list.contains(num)) {
                        list.add(num);
                } else continue;
                i++;
        }
        System.out.println(list.size());

        Num1Field.setText(list.remove(0) + "");
        Num2Field.setText(list.remove(0) + "");
        Num3Field.setText(list.remove(0) + "");
        Num4Field.setText(list.remove(0) + "");
        Num5Field.setText(list.remove(0) + "");
        Num6Field.setText(list.remove(0) + "");
        Num7Field.setText(list.remove(0) + "");
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ChooseByRandomJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ChooseByRandomJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ChooseByRandomJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ChooseByRandomJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ChooseByRandomJFrame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField Num1Field;
    private javax.swing.JLabel Num1Label;
    private javax.swing.JTextField Num2Field;
    private javax.swing.JLabel Num2Label;
    private javax.swing.JTextField Num3Field;
    private javax.swing.JLabel Num3Label;
    private javax.swing.JTextField Num4Field;
    private javax.swing.JLabel Num4Label;
    private javax.swing.JTextField Num5Field;
    private javax.swing.JLabel Num5Label;
    private javax.swing.JTextField Num6Field;
    private javax.swing.JLabel Num6Label;
    private javax.swing.JTextField Num7Field;
    private javax.swing.JLabel Num7Label;
    private javax.swing.JButton OKButton;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel9;
    // End of variables declaration//GEN-END:variables

}
